package terra.model.visual;

import org.newdawn.slick.Animation;
import org.newdawn.slick.Graphics;

import terra.managers.ResourceManager;
import terra.model.GameObject;
import terra.model.Player;
import terra.network.packet.server.ObjectMove;


public class PlayerVisualizator extends AbstractVisualizator {

	Animation[] animations = new Animation[ObjectMove.ANIMATION_MOVE];
	int currentAnimation;
	public Player owner;
	
	public PlayerVisualizator(){
		animations[ObjectMove.ANIMATION_ATTACK] = ResourceManager.getAnimation("player_"+ObjectMove.ANIMATION_ATTACK).copy();
		animations[ObjectMove.ANIMATION_MOVE] = ResourceManager.getAnimation("player_"+ObjectMove.ANIMATION_MOVE).copy();
		animations[ObjectMove.ANIMATION_STAND] = ResourceManager.getAnimation("player_"+ObjectMove.ANIMATION_STAND).copy();
	}
	
	@Override
	public void draw(Graphics g, GameObject object, float x, float y) {
		if (animations[currentAnimation] != null){
			animations[currentAnimation].draw(x, y);
		}
	}

	@Override
	public void update(int delta) {
		if (owner.getAnimationCurrent() != owner.getAnimationOld()){
			animations[owner.getAnimationOld()].restart();
			animations[owner.getAnimationCurrent()].restart();
			currentAnimation = owner.getAnimationCurrent();
			owner.setAnimationOld(owner.getAnimationCurrent());
		}
	}
	
	

}
